package cn.tedu.order.service;

import cn.tedu.order.entity.Order;
import cn.tedu.order.mapper.OrderMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Random;

@Service
@Slf4j
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderMapper orderMapper;
    @Override
    public void create(Order order) {
        //生成一个订单id
        // TODO: 2020/10/17  远程调用发号器，获得一个全局微议的id

        //临时生成一个id
        Long orderId = Long.valueOf(new Random().nextInt(999999999));
        order.setId(orderId);
        //保存订单
        orderMapper.create(order);
        log.info("保存订单成功，order="+order);
        // TODO: 2020/10/17 远程调用库存服务，减少商品库存
        // TODO: 2020/10/17 远程调用账号服务，扣减账户金额
    }
}
